package com.jl.slick.util.graphics.deprecated;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;


public class TS extends BE {

	//protected SpriteSheet tileset;       Inherited from SuperClass
	//protected Graphics background;
	String filename;
	final private int tilewidth, tileheight;
	private int filewidth, fileheight, maxtilewidth, maxtileheight;
	private Image rawimage;
	
	public TS(String file, int tilewidth, int tileheight) 
	{
		super("Tile Selector");
		this.filename = file;
		this.tilewidth = tilewidth;
		this.tileheight = tileheight;


		
	}
	

	@Override
	public void render(GameContainer arg0, Graphics background) throws SlickException 
	{
		for(int i = 0; i<(filewidth/tilewidth); i++) //draw full piece by piece
		{
			for(int j =0; j<(fileheight/tileheight); j++)
			background.drawImage(tileset.getSubImage(i, j), i*tilewidth, j*tileheight);
		}
	}

	
	@Override
	public void init(GameContainer container) throws SlickException 
	{	
		
			try {
				rawimage = new Image(filename);
				this.filewidth= rawimage.getWidth();
				this.fileheight= rawimage.getHeight();
				this.maxtilewidth = filewidth/tilewidth;
				this.maxtileheight = fileheight/tileheight;
			} catch (SlickException e) 
			{
				System.out.println("can't open file");
				rawimage = null;
				filewidth = 0;
				fileheight = 0;
				e.printStackTrace();
			}
			tileset = new SpriteSheet(rawimage, tilewidth, tileheight); //32x24 cells, 32x32 pixels each
			container = new AppGameContainer(this, filewidth, fileheight, false);
	}

	@Override
	public void update(GameContainer arg0, int arg1) throws SlickException 
	{
		
		
	}

}
